<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/7
 * Time: 22:53
 */
namespace App\Crontab;
use App\Service\StatMchService;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;

/**
 * @Crontab(name="StatMchDailyTask", rule="0 0 4 * * *", callback="execute", memo="商户统计执行任务每天凌晨4点执行")
 */
class StatMchDailyTask
{

    /**
     * @Inject()
     * @var \Hyperf\Contract\StdoutLoggerInterface
     */
    private $logger;

    /**
     * @Inject()
     * @var StatMchService
     */
    private $StatMchService;

    public function execute()
    {
        $this->logger->info('StatMchDailyTask 启动，当前时间：' . date('Y-m-d H:i:s', time()));

        // 默认取上一个天
        $statDate     = date('Y-m-d', strtotime("-1 day"));
        $statStartTime = strtotime($statDate." 00:00:00");
        $statEndTime   = strtotime($statDate." 23:59:59");

        $this->StatMchService->statDaily($statStartTime, $statEndTime, $statDate, [], false);

        $this->logger->info('StatMchDailyTask 执行完毕，当前时间：' . date('Y-m-d H:i:s', time()));
    }
}